package com.huijutao.utils;

import android.content.Context;

import com.huijutao.callback.StringDataCallBack;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

/**
 * Created by Administrator on 2015/4/18.
 */
public class StringXutils {
    public Context context;

    public StringXutils(Context context) {
        this.context = context;
    }

    public void downloadjson(String url,final StringDataCallBack data_callBack){

        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(1000 * 10);//设置超时时间
        http.send(HttpRequest.HttpMethod.GET, url, new RequestCallBack<String>() {
        //接口回调

            @Override
            public void onFailure(HttpException arg0, String arg1) {
                // TODO Auto-generated method stub
            }
            @Override
            public void onSuccess(ResponseInfo<String> info) {
                // TODO Auto-generated method stub
                data_callBack.stringDataCallBack(info.result);//利用接口回调数据传输
            }
        });
    }
    /**
     * 调用传入，实现回调拿到String的回调数据
     * @param path 路径
     * @param data_callBack 回调方法，String
     */
    public void getDataJson(String path,StringDataCallBack data_callBack) {
    //外部接口函数
        downloadjson(path,data_callBack);
    }
}
